package com.ruiyian.common.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruiyian.common.core.domain.entity.Equipment;
import com.ruiyian.common.core.domain.entity.SysDept;
import com.ruiyian.common.core.domain.entity.SysDictData;
import com.ruiyian.common.core.domain.entity.SysMenu;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author ruiyian
 */
@Data
public class TreeSelect implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    private Long id;

    /**
     * 节点名称
     */
    private String name;

    private String label;

    private String code;

    private Integer ifVirtual;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect() {

    }

    public TreeSelect(SysDept dept) {
        this.id = dept.getDeptId();
        this.name = dept.getDeptName();
        this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysDictData sysDictData) {
        this.id = sysDictData.getDictCode();
        this.label = sysDictData.getDictLabel();
        this.children = sysDictData.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysMenu menu) {
        this.id = menu.getMenuId();
        this.name = menu.getMenuName();
        this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }


    public TreeSelect(Equipment equipment) {
        this.id = equipment.getId();
        this.label = equipment.getName();
        this.code = equipment.getCode();
        this.ifVirtual = equipment.getIfVirtual();
    }


}
